package com.ruoyi.web.controller.material.mapper;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.web.controller.material.entity.ylSupplier;
import org.apache.ibatis.annotations.Mapper;

import javax.validation.constraints.NotBlank;

/**
 * 供应商信息Mapper接口
 *
 * @author jzx
 * @date 2025-10-21
 */
@Mapper
public interface SupplierMapper extends BaseMapper<ylSupplier> {
    /**
     * 获取供应商名称
     *
     * @param supplierName
     * @return
     */
    default boolean getWarehouseName(String supplierName, String id) {
        if (StringUtils.isNotEmpty(id)) {
            return selectCount(new LambdaQueryWrapper<ylSupplier>().eq(ylSupplier::getSupplierName, supplierName).ne(ylSupplier::getId, id)) > 0;
        }
        return selectCount(new LambdaQueryWrapper<ylSupplier>().eq(ylSupplier::getSupplierName, supplierName)) > 0;
    }

    ;

    /**
     * 根据id查询供应商名称
     *
     * @param supplierId
     * @return
     */
    default String getSupplierName(Long supplierId) {
        ylSupplier ylSupplier = selectById(supplierId);
        return ylSupplier == null ? "" : ylSupplier.getSupplierName();
    }

    ;


}
